<?php
$controller_name = trim($_POST['controller_name']);
$controller_name = ucfirst(strtolower($controller_name));

$file_name = $controller_name.'Controller.class.php';

define('CONTROLLER_ROOT', substr(dirname(__FILE__), 0, -10).'controllers/');

if(!is_dir(CONTROLLER_ROOT)) {
				
	mkdir(CONTROLLER_ROOT, 0777);
}

$controller_file = CONTROLLER_ROOT.$file_name;

if(file_exists($controller_file)){

	echo $controller_name,'的Controller文件已经存在';

	exit;
}
else{
    //创建CONTROLLER文件
	$file_content = "<?php\r\nclass ".$controller_name."Controller extends Controller {\r\n\r\n\tpublic function indexAction(){\r\n\r\n\t}\r\n}\r\n?>";
    
	$result = file_put_contents($controller_file, $file_content, LOCK_EX);

	//创建模板目录
	$template_dir = substr(dirname(__FILE__), 0, -10).'views/'.strtolower($controller_name);

	if(!is_dir($template_dir)){

		mkdir($template_dir, 0777);
	}

	if(!$result){

		echo $controller_name,'的Controller文件创建失败!';
	}
	else{

		echo $controller_name,'的Controller文件创建成功!';
	}
}
?>